/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hibernate;

import com.partaljevic.gambling.beans.Result;
import com.partaljevic.tapestry.gambling.service.ResultService;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;

/**
 *
 * @author Nemanja
 */
public class ResultServiceHibernate implements ResultService{

    private final Session session;

    public ResultServiceHibernate(Session session) {
        this.session = session;
    }

    @Override
    public Result save(Result result) {
//        session.save(result);
//        return result;
        return (Result) session.get(Result.class, session.save(result));
    }

    @Override
    public List<Result> retreive() {
        Criteria criteria = session.createCriteria(Result.class);
        return criteria.list();
    }

    @Override
    public Result retreive(Serializable id) {
        return (Result) session.get(Result.class, id);
    }

}
